﻿/*
* This software is the confidential and proprietary
* information of NetBay
* Such confidential information should not be disclosed
* NetBay copyright(c) 2011
*/
#region using
using System;
using System.Collections.Generic;
using System.Data;
using NetBay.Core.BusinessEntities.TaskManager;

#endregion

namespace Rio.Manager.Business.Repository.Translator
{
    class TaskManagerTranslator
    {
        /// <summary>
        /// GetTaskManager translation.
        /// </summary>
        /// <param name="P_oDbDataReader"></param>
        /// <returns></returns>
        public static List<TaskItem> GetTaskManager(IDataReader P_oDbDataReader)
        { 
            var l_lstReturnTaskManager = new List<TaskItem>(); 
            try
            {
                using (P_oDbDataReader)
                {
                    while (P_oDbDataReader.Read())
                    {
                        TaskItem _taskManager = new TaskItem();
                        _taskManager.MachineId = int.Parse(P_oDbDataReader["r_machine_id"].ToString());
                        _taskManager.Action = (TaskType)Enum.Parse(typeof(TaskType), P_oDbDataReader["r_action"].ToString());
                        _taskManager.StartTime = new TimeSpan(Convert.ToInt32(P_oDbDataReader["r_heuredebut"].ToString().Substring(0, 2)), Convert.ToInt32(P_oDbDataReader["r_heuredebut"].ToString().Substring(3, 2)), 0);
                        _taskManager.EndTime = new TimeSpan(Convert.ToInt32(P_oDbDataReader["r_heurefin"].ToString().Substring(0, 2)), Convert.ToInt32(P_oDbDataReader["r_heurefin"].ToString().Substring(3, 2)), 0);
                        _taskManager.Monday = Convert.ToBoolean(Convert.ToInt32(P_oDbDataReader["Lundi"].ToString()));
                        _taskManager.Tuesday = Convert.ToBoolean(Convert.ToInt32(P_oDbDataReader["Mardi"].ToString()));
                        _taskManager.Wednesday = Convert.ToBoolean(Convert.ToInt32(P_oDbDataReader["Mercredi"].ToString()));
                        _taskManager.Thursday = Convert.ToBoolean(Convert.ToInt32(P_oDbDataReader["Jeudi"].ToString()));
                        _taskManager.Friday = Convert.ToBoolean(Convert.ToInt32(P_oDbDataReader["Vendredi"].ToString()));
                        _taskManager.Saturday = Convert.ToBoolean(Convert.ToInt32(P_oDbDataReader["Samedi"].ToString()));
                        _taskManager.Sunday = Convert.ToBoolean(Convert.ToInt32(P_oDbDataReader["Dimanche"].ToString()));
                        l_lstReturnTaskManager.Add(_taskManager);                        
                    }
                }
            }
            catch (Exception ex)
            {
                NetBay.Core.Log.LogManager.Instance().LogError("EXCEPTION -> " + Environment.NewLine + ex);
            }
            return l_lstReturnTaskManager;
        }
    }
}